<!doctype html>
<html class="no-js" lang="">

<head>
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <title></title>
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <link rel="manifest" href="./site.webmanifest">
  <link rel="apple-touch-icon" href="./icon.png">
  <!-- Place favicon.ico in the root directory -->

  <link rel="stylesheet" href="./static/css/normalize.css">
  <link rel="stylesheet" href="./static/css/main.css">
  <link rel="stylesheet" href="./static/css/index.css">
  <link rel="stylesheet" href="./static/assets/css/zeroModal.css">
  <style type = “text/css”>   
a{text-decoration:none}
</style>  
</head>

<body>
  <!--[if lte IE 9]>
    <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="https://browsehappy.com/">upgrade your browser</a> to improve your experience and security.</p>
  <![endif]-->

  <!-- Add your site or application content here -->

<!--   <div class="header">
    <div class="header-container">
      <div class="title" onclick="goUrl('./index.html')">
        <img src="./static/img/jnsqywhglxmk.png" alt="">
        <img src="./static/img/glfupt.png" alt=""> </div>
      <ul class="info">
        <li id="header-username">
          <img src="./static/img/user.png" alt="">
          <a id="header-username" href="./login.html">登录</a>
        </li>
        <li>
          <img src="./static/img/config.png" alt="">
          <a href="./views/settings.html">设置</a>
        </li>
        <li>
          <img src="./static/img/message.png" alt="">
          <a href="./views/message.html">站内信</a>
        </li>
        <li>
          <a class="exit" onclick="doLogout()">退出</a>
        </li>
      </ul>
    </div>
  </div> -->

  <div class="main">
    <div class="container-box login">
      <div class="container-box-title">
        <img src="./static/img/title2.png" alt="">
      </div>

      <ul class="form">
        <li>
          <span>登录名：</span>
          <div class="input-box">
            <img src="./static/img/user-icon.png" alt="">
            <input class="input" type="text" name="username" id="username" value="">
          </div>
        </li>
        <li>
          <span>密&nbsp;&nbsp;码：</span>
          <div class="input-box">
            <img src="./static/img/password-icon.png" alt="">
            <input class="input" type="password" name="password" id="password" value="">
          </div>
        </li>
        <li>
          <span>验证码：</span>
          <input type="text" name="captchaz" id="captchaz" value="">
          <img alt="" id="captcha" onclick="refreshCaptcher();" src="" style="display: inline;width: 90px;height: 33px;"> 
          <a href="./views/forget.html" style="text-decoration:none;color: gray;">忘记密码?</a>
        </li>
        <li id="error_show">

        </li>
      </ul>

      <div class="actions" style="width: 300px">
        <button class="primary-btn" id="doLogin">登录</button>
        <button class="primary-btn" onclick="goUrl('./views/signin.html')">注册</button>
        <!-- <button class="primary-btn" onclick="goUrl('./views/forget.html')">忘记密码</button> -->
      </div>
    </div>

  </div>

  <div class="footer">
    <p>作者</p>
    <p>地址：</p>
    <p>邮政编码：250000 技术支持：</p>
  </div>

  <script src="./static/js/modernizr-3.6.0.min.js"></script>
  <script src="./static/js/jquery-1.12.min.js"></script>
  <script src="./static/js/jquery-md5.min.js"></script>
  <script src="./static/js/plugins.js"></script>
  <script src="./static/assets/scripts/zeroModal.min.js"></script>
  <script src="./static/js/main.js"></script>

  <!-- Google Analytics: change UA-XXXXX-Y to be your site's ID. -->
  <script>
    window.ga = function () {
      ga.q.push(arguments)
    };
    ga.q = [];
    ga.l = +new Date;
    ga('create', 'UA-XXXXX-Y', 'auto');
    ga('send', 'pageview')
  </script>

  <script>
    document.getElementById('doLogin').addEventListener('click', function (ev) {
      dologin();
    })

    function dologin() {
      var username = $.trim($("#username").val());
      var password = $.trim($("#password").val());
      var captcha = $.trim($("#captchaz").val());
      if (username.length < 1) {
        $("#error_show").empty();
        $("#error_show").html("<font color=\"red\">请输入用户名</font>");
        return;
      }
      if (password.length < 3) {
        //$("#username").empty();
        //$("#password").empty();
        $("#password").val();
        $("#error_show").empty();
        $("#error_show").html("<font color=\"red\">请输入密码</font>");
        $("#password").focus();
        return;
      }
      if (captcha.length < 3) {
        //$("#username").empty();
        //$("#password").empty();
        $("#captchaz").val();
        $("#error_show").empty();
        $("#error_show").html("<font color=\"red\">请输入验证码</font>");
        $("#captchaz").focus();
        return;
      }

      password = convertPassword(username, password);
      console.log("password:" + password);

      var param = {
        "username": username,
        "password": password,
        "captcha": captcha,
        "loginOrgin": "PC"
      };

      request({
        url: API_DOMAIN + 'api/auth/login',
        data: param,
        success: function (result) {
        	//refreshCaptcher();
          if (result.statusCode === 200) {
        	  //alert("登录成功");
            //goUrl('./index.html')
          } else {
        	  refreshCaptcher();
            zeroModal.alert(result.message);
          }
        }
      })
    }

    function convertPassword(username, password) {
      var salt = "zhtframework_94DABGioQOq2tTUO0AXYow";
      return hex_md5(salt + password);
    }

    function refreshCaptcher() {
      $('#captcha').hide().attr('src', API_DOMAIN+'api/auth/captcha?' + Math.floor(Math.random() * 100))
        .fadeIn();
    }

    $(function () {
      refreshCaptcher();
    });
  </script>
</body>

</html>